package com.jc.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 * 
 * ********************************************
 * 
 * @author lijiantao ********
 * @version 1.0, ****** 说明： 读取excel********
 **********************************************
 */
public class ReadExeclUtil {

	private static Workbook workbook;

	/**
	 * 功能：
	 * <p>
	 * 读取Excel表里的全部内容
	 * </p>
	 * 
	 * @param Excel 所在的绝对路径
	 */
	public static String readExcel(Map<Integer, String> map, String filePatch) {
		String json = "";
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		File file = new File(filePatch);
		// 文件只读
		file.setReadOnly();
		try {
			// 得到Excel文件
			workbook = Workbook.getWorkbook(file);

			// Excel中的工作表 下表从0开始
			Sheet sheet = workbook.getSheet(0);
			int row = sheet.getRows(); // 工作表共有的行
			for (int i = 3; i < row; i++) {
				Cell[] cells = sheet.getRow(i); // 拿一行的内容
				// System.out.println("cells=="+cells.length);
				Map<String, Object> map2 = new HashMap();
				for (int j = 0; j < cells.length; j++) {
					// System.out.println(cells[j].getContents() + "==");
					if (cells[j].getContents() == null || cells[j].getContents() == "") {
						map2.put(map.get(j), 0);
					} else {
						map2.put(map.get(j), cells[j].getContents());
					}

				}
				list.add(map2);
				// System.out.println();
			}
			json = JSONUtil.toGsonString(list);

		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (workbook != null) {
				workbook.close();
			}
		}
		// 还原文件状态
		file.canWrite();

		return json;
	}

	public static Map<String, List<Map<String, Object>>> readExcelAll(Map<Integer, String> map, String filePatch) {
		Map<String, List<Map<String, Object>>> rslt = new LinkedHashMap<String, List<Map<String, Object>>>();
		File file = new File(filePatch);
		// 文件只读
		file.setReadOnly();
		try {
			// 得到Excel文件
			workbook = Workbook.getWorkbook(file);
			Sheet[] sheets = workbook.getSheets();

			if (ArrayUtils.isNotEmpty(sheets)) {
				for (Sheet sheet : sheets) {
					List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
					int row = sheet.getRows(); // 工作表共有的行
					for (int i = 1; i < row; i++) {
						Cell[] cells = sheet.getRow(i); // 拿一行的内容
						// System.out.println("cells=="+cells.length);
						if (StringUtils.isBlank(cells[0].getContents())) {
							//							System.out.println(cells[0].getContents() + "==");
							continue;
						}
						Map<String, Object> map2 = new HashMap<String, Object>();
						for (int j = 0; j < cells.length; j++) {
							// System.out.println(cells[j].getContents() + "==");
							if (StringUtils.isBlank(cells[j].getContents())) {
								map2.put(map.get(j), null);
							} else {
								map2.put(map.get(j), cells[j].getContents().trim());
							}
						}
						list.add(map2);
						// System.out.println();
					}
					rslt.put(sheet.getName(), list);
				}
			}

		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (workbook != null) {
				workbook.close();
			}
			// 还原文件状态
			file.canWrite();
		}

		return rslt;
	}

	/**
	 * <p>
	 * 读取Excel表里的全部内容
	 * </p>
	 * @param Excel 所在的绝对路径
	 */
	public static String readExcel1(Map<Integer, String> map, String filePatch) {
		String json = "";
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		File file = new File(filePatch);
		// 文件只读
		file.setReadOnly();
		try {
			// 得到Excel文件
			workbook = Workbook.getWorkbook(file);

			// Excel中的工作表 下表从0开始
			Sheet sheet = workbook.getSheet(0);
			int row = sheet.getRows(); // 工作表共有的行
			for (int i = 1; i < row; i++) {
				Cell[] cells = sheet.getRow(i); // 拿一行的内容
				// System.out.println("cells=="+cells.length);
				Map<String, Object> map2 = new HashMap<String, Object>();
				for (int j = 0; j < cells.length; j++) {
					// System.out.println(cells[j].getContents() + "==");
					if (cells[j].getContents() == null || cells[j].getContents() == "") {
						map2.put(map.get(j), 0);
					} else {
						map2.put(map.get(j), cells[j].getContents());
					}

				}
				list.add(map2);
				// System.out.println();
			}
			json = JSONUtil.toGsonString(list);

		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (workbook != null) {
				workbook.close();
			}
		}
		// 还原文件状态
		file.canWrite();

		return json;
	}

	/**
	 * <dl>
	 * <dt>说明：读取excel</dt>
	 * <dd></dd>
	 * </dl>
	 * @author liujinlei
	 * @date 2018年3月9日 上午11:17:43
	 * @Title:readExcel
	 * @param map
	 * @param inputstream excel流
	 * @param starRow 开始读取行数 默认0 第一行开始读取
	 * @return String
	 */
	public static String readExcel(Map<Integer, String> map, InputStream inputstream, int starRow) {
		String json = "";
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			// 得到Excel文件
			workbook = Workbook.getWorkbook(inputstream);
			// Excel中的工作表 下表从0开始
			Sheet sheet = workbook.getSheet(0);
			int row = sheet.getRows(); // 工作表共有的行
			for (int i = starRow; i < row; i++) {
				Cell[] cells = sheet.getRow(i); // 拿一行的内容
				// System.out.println("cells=="+cells.length);
				Map<String, Object> map2 = new HashMap<String, Object>();
				for (int j = 0; j < cells.length; j++) {
					if (cells[j].getContents() == null || cells[j].getContents() == "") {
						map2.put(map.get(j), 0);
					} else {
						map2.put(map.get(j), cells[j].getContents());
					}
				}
				list.add(map2);
			}
			json = JSONUtil.toGsonString(list);

		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (workbook != null) {
				workbook.close();
			}
		}
		// 还原文件状态
		return json;
	}

	/**
	 * readExcel 读取excel
	 * @Title: readExcel
	 * @Description: TODO
	 * @param map
	 * @param filePatch excel文件路径
	 * @param startRow 开始读取行数 默认0 第一行开始读取
	 * @return 设定文件 String 返回类型
	 *********************************************************
	 */
	public static String readExcel(Map<Integer, String> map, String filePatch, int starRow) {
		String json = "";
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		File file = new File(filePatch);
		// 文件只读
		file.setReadOnly();
		try {
			// 得到Excel文件
			workbook = Workbook.getWorkbook(file);

			// Excel中的工作表 下表从0开始
			Sheet sheet = workbook.getSheet(0);
			int row = sheet.getRows(); // 工作表共有的行
			for (int i = starRow; i < row; i++) {
				Cell[] cells = sheet.getRow(i); // 拿一行的内容
				// System.out.println("cells=="+cells.length);
				Map<String, Object> map2 = new HashMap<String, Object>();
				for (int j = 0; j < cells.length; j++) {
					// System.out.println(cells[j].getContents() + "==");
					if (cells[j].getContents() == null || cells[j].getContents() == "") {
						map2.put(map.get(j), 0);
					} else {
						//						map2.put(map.get(j), cells[j].getContents());
						map2.put(map.get(j), cells[j].getContents().replaceAll("\\s*", ""));//去除所有空白字符
					}

				}
				list.add(map2);
				// System.out.println();
			}
			json = JSONUtil.toGsonString(list);

		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (workbook != null) {
				workbook.close();
			}
		}

		// 还原文件状态
		file.canWrite();
		return json;
	}

	/**
	 * 功能：
	 * <p>
	 * 读取2007Excel表里的全部内容
	 * </p>
	 * 
	 * @param Excel 所在的绝对路径
	 * @throws IOException
	 */
	public static String readExcel2007(Map<Integer, String> map, String filePatch) throws IOException {
		List<List<Object>> list = new LinkedList<List<Object>>();
		List<Map<String, Object>> listnew = new LinkedList<Map<String, Object>>();
		// 构造 XSSFWorkbook 对象，strPath 传入文件路径
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(filePatch));
		// 读取第一章表格内容
		XSSFSheet sheet = xwb.getSheetAt(0);
		Object value = null;
		XSSFRow row = null;
		XSSFCell cell = null;
		//System.out.println(sheet.getPhysicalNumberOfRows());
		for (int i = sheet.getFirstRowNum() + 1; i <= sheet.getPhysicalNumberOfRows(); i++) {
			Map<String, Object> map2 = new HashMap<String, Object>();
			row = sheet.getRow(i);
			if (row == null) {
				continue;
			}
			// List<Object> linked = new LinkedList<Object>();
			for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
				cell = row.getCell(j);
				if (cell == null) {
					continue;
				}
				DecimalFormat df = new DecimalFormat("0");// 格式化 number String
															// 字符
															// SimpleDateFormat
															// sdf = new
															// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
															// 格式化日期字符串
				DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
				switch (cell.getCellType()) {
					case XSSFCell.CELL_TYPE_STRING:
						// System.out.println(i+"行"+j+" 列 is String type");
						value = cell.getStringCellValue();
						break;
					case XSSFCell.CELL_TYPE_NUMERIC:
						// System.out.println(i+"行"+j+" 列 is Number type ; DateFormt:"+cell.getCellStyle().getDataFormatString()+cell.getNumericCellValue());
						if ("@".equals(cell.getCellStyle().getDataFormatString())) {
							value = df.format(cell.getNumericCellValue());
						} else if ("General".equals(cell.getCellStyle().getDataFormatString())) {
							value = nf.format(cell.getNumericCellValue());
						} else {
							// value =
							// sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
							value = cell.getNumericCellValue();
						}
						break;
					case XSSFCell.CELL_TYPE_BOOLEAN:
						// System.out.println(i+"行"+j+" 列 is Boolean type");
						value = cell.getBooleanCellValue();
						break;
					case XSSFCell.CELL_TYPE_BLANK:
						// System.out.println(i+"行"+j+" 列 is Blank type");
						value = "0";
						break;
					default:
						// System.out.println(i+"行"+j+" 列 is default type");
						value = cell.toString();
				}
				if (value == null || "".equals(value)) {
					value = "0";
					continue;
				}
				// System.out.println(value);
				// linked.add(value);
				map2.put(map.get(j), value);
			}
			// list.add(linked);
			listnew.add(map2);
		}
		return JSONUtil.toGsonString(listnew);
	}

	/**
	 * 
	 * @Title: readExcel2007
	 * @Description: 导出2007 版本的excel
	 * @param map
	 * @param filePatch excel文件路径
	 * @param startRow 开始读取行数 默认0 第一行开始读取
	 * @return String 返回类型
	 * @throws IOException 设定文件
	 *********************************************************
	 */
	public static String readExcel2007(Map<Integer, String> map, String filePatch, int startRow) throws IOException {
		String json = "";
		List<List<Object>> list = new LinkedList<List<Object>>();
		List<Map<String, Object>> listnew = new ArrayList<Map<String, Object>>();
		// 构造 XSSFWorkbook 对象，strPath 传入文件路径
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(filePatch));
		// 读取第一章表格内容
		XSSFSheet sheet = xwb.getSheetAt(0);
		Object value = null;
		XSSFRow row = null;
		XSSFCell cell = null;
		for (int i = sheet.getFirstRowNum() + startRow; i <= sheet.getPhysicalNumberOfRows(); i++) {
			Map<String, Object> map2 = new HashMap<String, Object>();
			row = sheet.getRow(i);
			if (row == null) {
				continue;
			}
			List<Object> linked = new LinkedList<Object>();
			for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
				cell = row.getCell(j);
				if (cell == null) {
					continue;
				}
				DecimalFormat df = new DecimalFormat("0");// 格式化 number String
															// 字符
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串
				DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
				switch (cell.getCellType()) {
					case XSSFCell.CELL_TYPE_STRING:
						// System.out.println(i+"行"+j+" 列 is String type");
						value = cell.getStringCellValue();
						break;
					case XSSFCell.CELL_TYPE_NUMERIC:
						// System.out.println(i+"行"+j+" 列 is Number type ; DateFormt:"+cell.getCellStyle().getDataFormatString()+cell.getNumericCellValue());
						if ("@".equals(cell.getCellStyle().getDataFormatString())) {
							value = df.format(cell.getNumericCellValue());
						} else if ("General".equals(cell.getCellStyle().getDataFormatString())) {
							value = nf.format(cell.getNumericCellValue());
						} else {
							// value =
							// sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
							value = cell.getNumericCellValue();
						}
						break;
					case XSSFCell.CELL_TYPE_BOOLEAN:
						// System.out.println(i+"行"+j+" 列 is Boolean type");
						value = cell.getBooleanCellValue();
						break;
					case XSSFCell.CELL_TYPE_BLANK:
						// System.out.println(i+"行"+j+" 列 is Blank type");
						value = "0";
						break;
					default:
						// System.out.println(i+"行"+j+" 列 is default type");
						value = cell.toString();
				}
				if (value == null || "".equals(value)) {
					value = "0";
					continue;
				}
				// System.out.println(value);
				linked.add(value);
				map2.put(map.get(j), value);
			}
			list.add(linked);
			listnew.add(map2);
		}
		json = JSONUtil.toGsonString(list);
		return json;
	}

	public static void main(String[] args) {
		Map<Integer, String> map = new HashMap<Integer, String>();
		map.put(0, "accountId");
		map.put(1, "recDate");
		map.put(2, "optUserId");
		map.put(3, "bank");
		map.put(4, "inAmount");
		map.put(5, "outAmount");
		map.put(6, "sysCkCode");
		map.put(7, "sysGzCode");
		map.put(8, "payWay");
		map.put(9, "payType");
		map.put(10, "itemType");
		map.put(11, "state");
		String json = readExcel(map, "D:\\Users\\lijiantao\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\iwms2\\WEB-INF\\upload\\asdf.xls");
		/*
		 * List<XzPay> list= (List) GsonUtils.jsonTolist(json,new
		 * TypeToken<List<XzPay>>(){}.getType()); for (XzPay xzPay : list) {
		 * System.out.println(xzPay.getOutAmount()); xzPay.getOutAmount(); }
		 */
	}

	/**
	 * 功能：
	 * <p>
	 * 张自来 读取2007Excel表里的全部内容
	 * </p>
	 * 
	 * @param Excel 所在的绝对路径
	 * @throws IOException
	 */
	/*public static String readExcelzzl2007(Map<Integer, String> map, String filePatch) throws IOException {
		List<List<Object>> list = new LinkedList<List<Object>>();
		List<Map<String, Object>> listnew = new LinkedList<Map<String, Object>>();
		// 构造 XSSFWorkbook 对象，strPath 传入文件路径
		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(filePatch));
		// 读取第一章表格内容
		XSSFSheet sheet = xwb.getSheetAt(0);
		Object value = null;
		XSSFRow row = null;
		XSSFCell cell = null;
		//System.out.println(sheet.getPhysicalNumberOfRows());
		for (int i = sheet.getFirstRowNum() + 1; i <= sheet.getPhysicalNumberOfRows(); i++) {
			Map<String, Object> map2 = new HashMap<String, Object>();
			row = sheet.getRow(i);
			if (row == null) {
				continue;
			}
			// List<Object> linked = new LinkedList<Object>();
			for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
				cell = row.getCell(j);
				if (cell == null) {
					continue;
				}
				DecimalFormat df = new DecimalFormat("0");// 格式化 number String
															// 字符
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

				// //
				// 格式化日期字符串
				DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
				switch (cell.getCellType()) {
					case XSSFCell.CELL_TYPE_STRING:
						// System.out.println(i+"行"+j+" 列 is String type");
						//						value = cell.getStringCellValue();
						value = cell.getStringCellValue().replaceAll("\\s*", "");//去除空白字符
						break;
					case XSSFCell.CELL_TYPE_NUMERIC:
						// System.out.println(i+"行"+j+" 列 is Number type ; DateFormt:"+cell.getCellStyle().getDataFormatString()+cell.getNumericCellValue());
						if ("@".equals(cell.getCellStyle().getDataFormatString())) {
							value = df.format(cell.getNumericCellValue());
						} else if ("General".equals(cell.getCellStyle().getDataFormatString())) {
							value = df.format(cell.getNumericCellValue());
						} else {
							value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
							//value = cell.getNumericCellValue();
						}
						break;
					case XSSFCell.CELL_TYPE_BOOLEAN:
						// System.out.println(i+"行"+j+" 列 is Boolean type");
						value = cell.getBooleanCellValue();
						break;
					case XSSFCell.CELL_TYPE_BLANK:
						// System.out.println(i+"行"+j+" 列 is Blank type");
						value = "0";
						break;
					case XSSFCell.CELL_TYPE_FORMULA:
						if (HSSFDateUtil.isCellDateFormatted(cell)) {
							// 如果是Date类型则，取得该Cell的Date值
							Date date = cell.getDateCellValue();
							// 把Date转换成本地格式的字符串
							value = cell.getDateCellValue().toLocaleString();
						}
						// 如果是纯数字
						else {
							// 取得当前Cell的数值
							double num = new Double((double) cell.getNumericCellValue());
							value = "";
							try {
								value = cell.getStringCellValue();
							} catch (Exception ex) {
								System.out.println("execl 解析错误 : " + ex.getMessage());
							}
						}
						break;
					default:
						value = cell.toString();
				}
				if (value == null || "".equals(value)) {
					value = "0";
					continue;
				}
				// System.out.println(value);
				// linked.add(value);
				map2.put(map.get(j), value);
			}
			// list.add(linked);
			listnew.add(map2);
		}
		return JSONUtil.toGsonString(listnew);
	}*/
	/**  
	   * @Title: readExcelzzl2007  
	   * @Description: 读取2007Excel  
	   * @param @param map
	   * @param @param filePatch
	   * @param @return
	   * @param @throws IOException    参数  
	   * @return String    返回类型  
	 * @throws InvalidFormatException 
	 * @throws EncryptedDocumentException 
	*/  
	public static String readExcelzzl2007(Map<Integer, String> map, String filePatch) throws IOException, EncryptedDocumentException, InvalidFormatException {
		List<Map<String, Object>> listnew = new LinkedList<Map<String, Object>>();
		// 构造 XSSFWorkbook 对象，strPath 传入文件路径
//		XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(filePatch));
		InputStream inputStream=new FileInputStream(filePatch);
		XSSFWorkbook xwb = (XSSFWorkbook)WorkbookFactory.create(inputStream);
		// 读取第一章表格内容
		XSSFSheet sheet = xwb.getSheetAt(0);
//		System.out.println("总行数："+sheet.getPhysicalNumberOfRows()+"&&数据不为空的行："+sheet.getLastRowNum());
		Object value = null;
		XSSFRow row = null;
		XSSFCell cell = null;
		//System.out.println(sheet.getPhysicalNumberOfRows());
		for (int i = sheet.getFirstRowNum() + 1; i <= sheet.getPhysicalNumberOfRows(); i++) {
			Map<String, Object> map2 = new HashMap<String, Object>();
			row = sheet.getRow(i);
			if (row == null) {
				continue;
			}
			// List<Object> linked = new LinkedList<Object>();
			for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
				cell = row.getCell(j);
				if (cell == null) {
					continue;
				}
				DecimalFormat df = new DecimalFormat("0");// 格式化 number String
															// 字符
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

				// //
				// 格式化日期字符串
//				DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
				switch (cell.getCellType()) {
					case XSSFCell.CELL_TYPE_STRING:
						// System.out.println(i+"行"+j+" 列 is String type");
						//						value = cell.getStringCellValue();
						value = cell.getStringCellValue().replaceAll("\\s*", "");//去除空白字符
						break;
					case XSSFCell.CELL_TYPE_NUMERIC:
						// System.out.println(i+"行"+j+" 列 is Number type ; DateFormt:"+cell.getCellStyle().getDataFormatString()+cell.getNumericCellValue());
						if ("@".equals(cell.getCellStyle().getDataFormatString())) {
							value = df.format(cell.getNumericCellValue());
						} else if ("General".equals(cell.getCellStyle().getDataFormatString())) {
							value = df.format(cell.getNumericCellValue());
						} else {
							value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
							//value = cell.getNumericCellValue();
						}
						break;
					case XSSFCell.CELL_TYPE_BOOLEAN:
						// System.out.println(i+"行"+j+" 列 is Boolean type");
						value = cell.getBooleanCellValue();
						break;
					case XSSFCell.CELL_TYPE_BLANK:
						// System.out.println(i+"行"+j+" 列 is Blank type");
						value = "0";
						break;
					case XSSFCell.CELL_TYPE_FORMULA:
						if (HSSFDateUtil.isCellDateFormatted(cell)) {
							// 如果是Date类型则，取得该Cell的Date值
//							Date date = cell.getDateCellValue();
							// 把Date转换成本地格式的字符串
							value = cell.getDateCellValue().toLocaleString();
						}
						// 如果是纯数字
						else {
							// 取得当前Cell的数值
//							double num = new Double((double) cell.getNumericCellValue());
							value = "";
							try {
								value = cell.getStringCellValue();
							} catch (Exception ex) {
								System.out.println("execl 解析错误 : " + ex.getMessage());
							}
						}
						break;
					default:
						value = cell.toString();
				}
				if (value == null || "".equals(value)) {
					value = "0";
					continue;
				}
				// System.out.println(value);
				// linked.add(value);
				map2.put(map.get(j), value);
			}
			// list.add(linked);
			listnew.add(map2);
		}
		inputStream.close(); 
		xwb.close();
		return JSONUtil.toGsonString(listnew);
	}
}
